﻿@inject IMessageService MessageService
@inject IDialogService DialogService
@using FluentUI.Demo.Shared.Pages.Dialog.Examples;



<FluentButton OnClick="@AddInTopBar" Appearance="Appearance.Accent">Add on top</FluentButton>
<FluentButton OnClick="@AddInNotificationCenter" Appearance="Appearance.Accent">Add in Notification Center</FluentButton>
<FluentButton OnClick="@AddInDialog" Appearance="Appearance.Accent">Add in a dialog</FluentButton>

<FluentButton Appearance="Appearance.Neutral" OnClick="@((e) => MessageService.Clear())">Clear all alerts</FluentButton>

@code
{
    SimplePerson simplePerson = new()
        {
            Firstname = "Dan",
            Lastname = "Sanderson",
            Age = 42,
        };

    ActionLink<Message> link = new()
        {
            Text = "Learn more",
            Href = "https://bing.com",
            OnClick = (e) => { DemoLogger.WriteLine($"Message 'learn more' clicked"); return Task.CompletedTask; }
        };

    int counter = 0;

    void AddInTopBar()
    {
        var message = $"Simple message #{counter++}";
        var type = Enum.GetValues<MessageIntent>()[counter % 4];
        MessageService.ShowMessageBarAsync(message, type, App.MESSAGES_TOP);
    }

    void AddInNotificationCenter()
    {
        MessageService.ShowMessageBar(options =>
        {
            options.Intent = Enum.GetValues<MessageIntent>()[counter % 4];
            options.Title = $"Simple message #{counter++}";
            options.Body = MessageBarSamples.OneRandomMessage;
            options.Link = link;
            options.Timestamp = DateTime.Now;
            options.Section = App.MESSAGES_NOTIFICATION_CENTER;
        });
    }


    async Task AddInDialog()
    {
        MessageService.ShowMessageBar(options =>
        {
            options.Intent = Enum.GetValues<MessageIntent>()[counter % 4];
            options.Title = $"Simple message #{counter++}";
            options.Body = MessageBarSamples.OneRandomMessage;
            options.Link = link;
            options.Timestamp = DateTime.Now;
            options.Section = App.MESSAGES_DIALOG;
        });

        await OpenDialogAsync();
    }

    private async Task OpenDialogAsync()
    {
        DialogParameters<SimplePerson> parameters = new()
            {
                Title = $"Hi {simplePerson.Firstname}!",
                PrimaryAction = "Yes",
                PrimaryActionEnabled = false,
                SecondaryAction = "No",
                Width = "500px",
                Height = "500px",
                Content = simplePerson,
                TrapFocus = true,
                Modal = true,
            };

        IDialogReference dialog = await DialogService.ShowDialogAsync<SimpleDialog>(simplePerson, parameters);
        DialogResult? result = await dialog.Result;
    }
}